﻿@if(!Svc.IsAuthenticated)
{
    <a href="@Url.Action(Loc.Act("SignIn").Ctrl("Access").NoArea().Localized())">@T(Res.Name("Buy"))</a>
}
else
{
    var stock = (Model.StockEntries as IEnumerable<dynamic>).FirstOrDefault();
    if(stock == null)
    {
        <a href="@Url.Action(Loc.Act("Put").Ctrl("ShoppingCart").Area("Wizard").Set(new
        {
            salesItemID = JDM.Int32(Model.EntityID),
            price = Svc.Price((decimal)JDM.Decimal(Model.Price)),
            quantity = 1
        }).Localized())">@T(Res.Name("Buy"))</a>
    }
    else if(JDM.Decimal(stock.AdjustmentMin) > JDM.Decimal(stock.Reserve) && 
        !JDM.HasFlags(stock.Flags, "OversoldAllowed"))
    {
        <a class="inactive" href="#">@T(Res.Name("Buy"))</a>
    }
    else
    {
        <a href="@Url.Action(Loc.Act("Put").Ctrl("ShoppingCart").Area("Wizard").Set(new
        {
            salesItemID = JDM.Int32(Model.EntityID),
            price = Svc.Price((decimal)JDM.Decimal(Model.Price)),
            quantity = JDM.Decimal(stock.AdjustmentMin)
        }).Localized())">@T(Res.Name("Buy"))</a>
    }
}